class Solution:
    def maxProfit(self , prices ):
        # write code here
        if len(prices)<2:
            return 0
        buy = prices[0]
        profit = 0
        for i in range(1,len(prices)):
            if prices[i] < buy: buy = prices[i]
            profit = max(profit,prices[i] - buy)
        return profit